package com.yueqian.Service;


import com.yueqian.Dao.UpdateEmployeeDao;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 修改员工信息
 */
@WebServlet(urlPatterns = "/UpdateEmployeeService")
public class UpdateEmployeeService extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       req.setCharacterEncoding("utf-8");
        String  number = req.getParameter("id");
        String username =  req.getParameter("username");
        String password =  req.getParameter("password");
        UpdateEmployeeDao updateEmployeeDao = new UpdateEmployeeDao();
        boolean b=false;
        System.out.println(number);
        if(number == null)
          {
              System.out.println("传输数据为空");
              req.setAttribute("message1","请输入员工编号不能空");
          }
          else if(username!=null&&password!=null){
             b = updateEmployeeDao.updateUser(number, username, password);
        }
          else if(username!=null&&password==null){
              b = updateEmployeeDao.updateUsername(number, username);
        }
          else if(password!=null&&username==null){
              b = updateEmployeeDao.updatePassword(number, password);
        }
          if(b)
          {
              System.out.println("修改成功");
              req.setAttribute("message1","修改成功");
              resp.sendRedirect("GetEmployee.jsp");
//              req.getRequestDispatcher("update.jsp").forward(req,resp);
          }
           else
          {
              System.out.println("修改失败");
              req.setAttribute("message1","修改失败");
              req.getRequestDispatcher("update.jsp").forward(req,resp);
          }
    }
}
